package org.bigtree.example.common.frame.listener;

import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionActivationListener;
import jakarta.servlet.http.HttpSessionEvent;
import lombok.extern.slf4j.Slf4j;

/**
 * @author bigTree
 * @since 2025/6/14
 */
@Slf4j
public class SessionScopeListener implements HttpSessionActivationListener {
    @Override
    public void sessionWillPassivate(HttpSessionEvent se) {
        log.info("session will passivate");
        HttpSession session = se.getSession();
        String id = session.getId();
        long lastAccessedTime = session.getLastAccessedTime();
        log.info("session id: {}, lastAccessedTime: {}", id, lastAccessedTime);
    }

    @Override
    public void sessionDidActivate(HttpSessionEvent se) {
        log.info("session activated");
        HttpSession session = se.getSession();
        String id = session.getId();
        long creationTime = session.getCreationTime();
        session.setMaxInactiveInterval(10);
        log.info("session id: {}, creationTime: {}", id, creationTime);
    }
}
